<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$id=$_RQ['getlogid'];
	if(!$id){
		exi('优惠券不存在！','error');
	}	
	$log=pdo_get('jy_weishop_coupon_getlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$coupon=$this->model('coupon')->intcoupon($log['couponid'],$log['createtime']);
	$coupon['limitgoodids']= explode(';', $coupon['limitgoodids']);
	$coupon['limitgoodids']= substr(implode(',', $coupon['limitgoodids']),1,strlen(implode(',', $coupon['limitgoodids']))-2);
	$coupon['limitgoodcateids']= explode(';', $coupon['limitgoodcateids']);
	$coupon['limitgoodcateids']= substr(implode(',', $coupon['limitgoodcateids']),1,strlen(implode(',', $coupon['limitgoodcateids']))-2);
	if ($coupon['limitgoodtype'] != 0) {
		if (!empty($coupon['limitgoodids'])) {
			$where = 'and id in(' . $coupon['limitgoodids'] . ')';
		}
		$goods = pdo_fetchall('select `title` from ' . tablename('jy_weishop_goods') . ' where uniacid=:uniacid ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
	}
	if ($coupon['limitgoodcatetype'] != 0) {
		if (!empty($coupon['limitgoodcateids'])) {
			$where = 'and id in(' . $coupon['limitgoodcateids'] . ')';
		}
		$group = pdo_fetchall('select `title`  from ' . tablename('jy_weishop_goods_group') . ' where uniacid=:uniacid   ' . $where, array(':uniacid' => $_SESSION['uniacid']), 'id');
	}
	$return['setting']=$this->plugin_setting('coupon');
	$return['goods']=$goods;
	$return['group']=$group;
	$coupon['hexiaourl']=custom_url('jy_weishop/coupon.hexiao//getlogid='.$id,true);
	$return['coupon']=$coupon;
	$return['post']=array(
		'getlogid'=>$log['id'],
		'fmid'=>$log['mid'],
	);
	set_html('title','优惠券详情');
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$getlogid=intval($post['getlogid']);
	$fmid=intval($post['fmid']);
	pdo_update('jy_weishop_coupon_getlog',array('mid'=>$_SESSION['uid'],'fmid'=>$fmid),array('uniacid'=>$_SESSION['uniacid'],'id'=>$getlogid));
	exi('领取成功！','','jy_weishop/coupon.myindex/');
}
?>